import React from 'react';
import axios from 'axios';

export default class About extends React.PureComponent {

    static async getInitialProps(param) {
        //这段在服务端执行
        console.log(param);
        //let result = await axios.get('http://t.weather.sojson.com/api/weather/city/101030100');
        //console.log(result.data);
        //返回的数据会传给constructor
        return { title: 'a', content: 'b' };
    }

    constructor(props) {
        super(props);

        this.state = {
            name: '张三',
            age: 20,
        }
        console.log('props', props);
        console.log(props.url.query);
    }

    componentDidMount() {
        console.log('componentDidMount');
    }

    render() {
        const user = () => {
            return <h2>{this.state.name}-{this.state.age}</h2>
        };
        return (
            <div>
                <h1>hello!</h1>
                {user()}
                <img src="/zeit.svg"></img>
                <pre>
                Context Object
getInitialProps receives a single argument called context, it's an object with the following properties:

pathname - Current route. That is the path of the page in /pages
query - Query string section of URL parsed as an object
asPath - String of the actual path (including the query) shown in the browser
req - HTTP request object (server only)
res - HTTP response object (server only)
err - Error object if any error is encountered during the rendering
                </pre>
            </div>
        )
    }

}